// pages/server_end/mine/mine.js
const app = getApp();
const request = require('../../../utils/request.js');
const url = require('../../../utils/url.js');
const cookie = require('../../../utils/cookie.js');

Page({
  /**
   * 页面的初始数据
   */
  data: {
    userinfo:[],
    token:'',
	curcity:'',
	pay_money:0,
	servertype:''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this;
    cookie.getCookie('userInfo', function (res) {
      if (res) {
        var etime = Date.parse(new Date()) / 1000;
        
        if (etime < res.expiretime) {
          that.setData({
            login: 1,
            token:res.token
          })
          that.getWorkerInfo();
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  goLogin: function () {
    console.log('登录');
    wx.navigateTo({
      url: '../../authorization/authorization'
    })
  },
  getWorkerInfo:function(){
    var that = this;
    let param = {
      scoure: 'wxapp',
      token:that.data.token
    }
    wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
    request.request(url.workerinfo, param, url.REQUEST_METHOD_GET).then((res) => {
      wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
      if(res.data.code==1){
         that.setData({
             userinfo : res.data.data,
			 curcity:res.data.data.citytxt,
			 pay_money:res.data.data.pay_money,
			 servertype:res.data.data.service_category_id
         })
       }
    })  	
  },
  goEdit(){
	  console.log('xxxxxxxxxxxxxxxxx');
    wx.navigateTo({
      url:'../user_info/user_info'
    })			
  },
  goDraw(){
    wx.navigateTo({
      url:'../withdrawals/withdrawals'
    })
  },
  goPoster(){
     wx.navigateTo({
       url:'../posters/posters'
     })
  },
  goIncome(){
    wx.navigateTo({
      url:'../income/income'
    })
  },
  goQuestion(){
    wx.navigateTo({
      url:'../question/question'
    })
  },

  wysq(){
	  
    wx.navigateTo({
      url:'../mine_sq/mine_sq?city='+this.data.curcity
    })
 },

	
stopservice(){
	wx.navigateTo({
	  url:'../stop_service/stop_service?pay_money='+this.data.pay_money
	})
},
addservertype(){
	wx.navigateTo({
	  url:'../add_servertype/add_servertype?servertype='+this.data.servertype
	})
},
  goContractList(){
    if (this.data.login == 0) {
      this.goLogin();
      return false;
    }
    wx.navigateTo({
      url: '../contract_list/contract_list'
    })
  },


  loginout:function(){
      cookie.setCookie('userInfo', null);  
    wx.showToast({
      title:'退出成功!',
      icon:'none'
    });	
     this.goLogin();
    },



  goChange: function () {
    if (this.data.login == 0) {
      this.goLogin();
      return false;
    }
    wx.navigateTo({
      url: '../../select_identity/select_identity'
    })
  },
})